const express = require('express');
const { makeMiddleware } = require('./rendertron_middleware.js')
const { Rendertron } = require('./rendertron/index');
const history = require("connect-history-api-fallback")

const rendertron = new Rendertron()
const botUserAgents = [
    'baiduspider',
    'bingbot',
    'embedly',
    'facebookexternalhit',
    'linkedinbot',
    'outbrain',
    'pinterest',
    'quora link preview',
    'rogerbot',
    'showyoubot',
    'slackbot',
    'TelegramBot',
    'twitterbot',
    'vkShare',
    'W3C_Validator',
    'whatsapp',
];
const rendertron_config = {
  "port": 7003,
  "width": 960,
  "height": 540,
  "timeout": 3000,
  "cache": "filesystem"
}
rendertron.initialize(rendertron_config)
const app = express()
app.use(history())
let port = 7004
app.use(makeMiddleware({
  proxyUrl: 'http://127.0.0.1:7003/render/',
  botUserAgents
}))
app.use(express.static('dist'))
app.listen(port, function () {
  console.log(`Express App Starting on port ${port}`)
})